package models

import (
	"gorm.io/datatypes"
	"gorm.io/gorm"
)

type Product struct {
	gorm.Model    `gorm:"embedded"`
	CategoryID    uint           `gorm:"not null;index;comment:分类ID" json:"category_id"`
	Name          string         `gorm:"size:100;not null;comment:商品名称" json:"name"`
	Description   string         `gorm:"varchar(100);comment:商品描述" json:"description"`
	Price         float64        `gorm:"type:decimal(10,2);not null;comment:售价" json:"price"`
	OriginalPrice float64        `gorm:"type:decimal(10,2);comment:原价" json:"original_price,omitempty"`
	Discount      float64        `gorm:"type:decimal(10,2);comment:折扣" json:"discount"`
	Stock         int            `gorm:"default:0;comment:库存" json:"stock"`
	SoldCount     int            `gorm:"default:0;comment:已售数量" json:"sold_count"`
	MainImage     string         `gorm:"size:255;not null;comment:主图URL" json:"main_image"`
	DetailImages  datatypes.JSON `gorm:"type:json;comment:详情图URL数组" json:"detail_images"`
}

type ProductCategory struct {
	gorm.Model `gorm:"embedded"`
	Name       string `gorm:"size:50;not null;comment:分类名称" json:"name"`
	Icon       string `gorm:"size:255;comment:图标URL" json:"icon"`
	Count      int    `gorm:"default:0;comment:类别商品件数" json:"count"`
	IsVisible  bool   `gorm:"default:true;comment:是否显示" json:"is_visible"`

	// 关联关系
	//Products []Product `gorm:"foreignKey:CategoryID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-"`
}

type HotProduct struct {
	gorm.Model  `gorm:"embedded"`
	Title       string `gorm:"size:50;not null;comment:标题" json:"title"`
	Description string `gorm:"varchar(100);comment:商品描述" json:"description"`
	MainImage   string `gorm:"size:255;not null;comment:主图URL" json:"main_image"`
}
